#项目的根路由文件
"""
URL configuration for my_blog project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include
# 添加 redirect 导入
from django.shortcuts import redirect
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static

#自定义管理后台的标题:
admin.site.site_header = "ShareWave 博客-管理后台"  # 登录页面和管理后台页面的标题
admin.site.site_title = "站点管理"  # 浏览器标签页的标题
admin.site.index_title = "ShareWave 博客-管理后台"  # 首页标题
# 存放映射关系的列表
urlpatterns = [
    path('admin/', admin.site.urls),
    # 新增代码，配置app的url
    #保参数article/分配了app的访问路径
    #include将路径分发给下一步处理；
    #namespace可以保证反查到唯一的url，即使不同的app使用了相同的url
    path('article/', include('article.urls', namespace='article')),
    # 添加根路径的重定向
    path('', lambda request: redirect('article:article_list'), name='root'),
    # 用户管理
    path('userprofile/', include('userprofile.urls', namespace='userprofile')),
    #重置密码
    # path('password_reset/', include('password_reset.urls', name='password_reset')),
        # 密码重置 URLs - 确保名称与默认模板一致
    path('password-reset/', 
        auth_views.PasswordResetView.as_view(
            template_name='password_reset/password_reset_form.html',
            email_template_name='password_reset/password_reset_email.html',
            subject_template_name='password_reset/password_reset_subject.txt'
        ),
        name='password_reset'),
        path('password-reset/done/',
        auth_views.PasswordResetDoneView.as_view(
            template_name='password_reset/password_reset_done.html'
        ),
        name='password_reset_done'),
    
    path('reset/<uidb64>/<token>/',
        auth_views.PasswordResetConfirmView.as_view(
            template_name='password_reset/password_reset_confirm.html',
            success_url='/reset/done/'
        ),
        name='password_reset_confirm'),
    
    path('reset/done/',
        auth_views.PasswordResetCompleteView.as_view(
            template_name='password_reset/password_reset_complete.html'
        ),
        name='password_reset_complete'),
    # django-allauth第三方登录
    path('accounts/', include('allauth.urls')),
    # 评论
    path('comment/', include('comment.urls', namespace='comment')),
    # 添加 CKEditor5 的 URL
    path("ckeditor5/", include('django_ckeditor_5.urls')),
    
]
#媒体-图片上传配置
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)